﻿// BlueprintScriptLibrary.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "BlueprintScriptLibrary/Var.h"
#include "BlueprintScriptLibrary/Pin.h"
#include "BlueprintScriptLibrary/Reflections.h"
#include "BlueprintScriptLibrary/RegistAction.h"
#include "MyClass.h"

using namespace BlueprintScriptLibrary;

//使用c++的方式实现一个函数
class AddPin : public FunctionPin
{
public:
	AddPin() {}
	void Execute()
	{
		if (GetInputVarableNum() > 2) return;
		VarBaseInt* par0 = dynamic_cast<VarBaseInt*>(*input);
		VarBaseInt* par1 = dynamic_cast<VarBaseInt*>(*(input + 1));
		output[0].val = par0->val + par1->val;
	}
	virtual void SetInputParameters(Var** para)
	{
		if (para != nullptr)  input[0] = *para;
		if (para + 1 != nullptr)  input[1] = *(para + 1);
	}
	virtual class Var** GetInputParameters() { return nullptr; }
	virtual int GetInputVarableNum() { return 2; }


	int GetOutputPinNums() override
	{
		return 1;
	}

	Var** GetOutputResult() override
	{
		Var* v = output;
		return &v;
	}
	BlueprintScriptLibrary::Class* GetClass() { return nullptr; }
private:
	VarBaseInt output[1]{ 0 };
	Var* input[2];
};
RegisterBlueprintFunction(AddPin)

class CustomDefineFunc : public FunctionPin
{
public:
	void Execute()
	{
		Pin* next = beginPin.GetConnectNextPin();
		SolvePin(next);
	}
	virtual void SetInputParameters(Var** para)
	{
	}
	virtual class Var** GetInputParameters() { return nullptr; }
	virtual int GetInputVarableNum() { return 2; }


	int GetOutputPinNums() override
	{
		return 1;
	}

	Var** GetOutputResult() override
	{
		Var* v = result;
		return &v;
	}

private:
	BeginPin beginPin;
	VarBaseInt result[1];
};



int main()
{

	using namespace std;
	//pin的调用
	{
		//使用代码调用函数
		FunctionPin* addPinFunc = BlueprintDataPool::GetInstance()->allFunctionObjs[0];
		Var* input[2];
		input[0] = new VarBaseInt(4);
		input[1] = new VarBaseInt(2);
		((AddPin*)addPinFunc)->SetInputParameters(input);
		addPinFunc->Execute();
		Var* va = *addPinFunc->GetOutputResult();
		VarBaseInt* vbii = dynamic_cast<VarBaseInt*>(va);
		std::cout << vbii->val << std::endl;
		delete input[0];
		delete input[1];
	}
	//pin的接口访问
	
	//------------------------------------------
	//获取名称
	cout << BlueprintDataPool::GetInstance()->allClass[0] << endl;
	//获取对应的class,这个class一般是对蓝图使用的，可以操作对象，并且调用成员函数和成员变量
	cout << "class nums" << BlueprintDataPool::GetInstance()->allClassTables.size() << endl;
	BlueprintScriptLibrary::Class* c = BlueprintDataPool::GetInstance()->allClassTables[0];
	//{
	cout << endl;
	cout << c->GetObjectVariableNums() << endl;
	cout << c->GetObjectFunctionPinNums() << endl;
	cout << c->GetObjectFunctionPins() << endl;
	//------------------------------------------
	MyClass mc;
	/*	Array<VarBaseInt>  inputPara(1);
		inputPara.data[0]*/

		/*cout << "offset bellow" << endl;
		cout << offsetof(MyClass,a)/8 << endl;
		cout << offsetof(MyClass,b) / 8 << endl;
		cout << offsetof(MyClass,c) / 8 << endl;
		cout << offsetof(MyClass,d) / 8 << endl;
		cout << offsetof(MyClass,vbia) / 8 << endl;
		cout << offsetof(MyClass,vbfb) / 8 << endl;
		cout << offsetof(MyClass,vbbc) / 8 << endl;
		cout << offsetof(MyClass,vbsd) / 8 << endl;
		cout << "-------------endl" << endl;
		cout << sizeof(Var) << endl;
		cout << sizeof(VarBaseInt) << endl;
		cout << sizeof(*v) << endl;
		cout << "-------------endl" << endl;
		int av = 132;
		mc.a = 111;
		mc.b = 22;

		unsigned int pO = (unsigned int)&mc;
		unsigned int p1 = (unsigned int)&mc.vbia;
		cout << sizeof(VarBaseInt)<< endl;
		char* vpo = ( char*)pO;
		memcpy((void*)(pO + offsetof(MyClass, vbia)), v, sizeof(*v));*/
		//memcpy((void*)p1, &vbi, 36);
		//*(VarBaseInt*)p1 = *v;
		//*(int*)p1 = av;

	{
		VarBaseInt vbi;
		vbi.val = 12;
		VarBaseInt* v = &vbi;

		cout << mc.vbia.val << endl;
		Var* pV = &vbi;
		//设置成员变量
		c->SetMembersInObjInst("vbia", &mc, pV);
		VarBaseFloat vbf;
		vbf.val = 3.14156;
		pV = &vbf;
		c->SetMembersInObjInst("vbfb", &mc, pV);
		//delete vbf;

		Object* inst = c->CreateInstance();
	/*VarBaseBool vbb;
	vbb.val = false;
	c->SetMembersInObjInst("vbbc", &mc, &vbb);*/
		VarBaseString vbs;
		vbs.val = "helloworld";
		c->SetMembersInObjInst("vbsd", &mc, &vbs);

		cout << "set members result like follow:" << endl;
		cout << mc.vbia.val << endl;
		Var* valOfMc1 = c->GetMembersInObj("vbia", &mc);
		Var* valOfMc2 = c->GetMembersInObj("vbfb", &mc);
		Var* valOfMc3 = c->GetMembersInObj("vbbc", &mc);
		Var* valOfMc4 = c->GetMembersInObj("vbsd", &mc);
		cout << valOfMc1->ToString() << endl;
		cout << valOfMc2->ToString() << endl;
		cout << valOfMc3->ToString() << endl;
		cout << valOfMc4->ToString() << endl;
	}
	//VarBaseInt vbi;
	//vbi.val = 222223;
	//Var* inputV[1];
	//inputV[0] = &vbi;
	//调用函数
	//c->CallMethod("SetVbia", &mc, inputV, nullptr);
	//cout << valOfMc1->ToString() << endl;
	return 0;
}
